package com.class05.chain;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@WebFilter(
//        过滤器名称
        filterName = "loggingFilter",
//        过滤器过滤的参数
        initParams = {@WebInitParam(name="dateTimePattern"
                ,value="yyyy-MM-dd HH:mm:ss")},
//        过滤器过滤的路径
        urlPatterns = {"/testA","*.html"},
//        过滤器过滤的servlet名称
        servletNames = {"servletBName"}
)
public class FilterB implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        String dateTimePattern = filterConfig.getInitParameter("dateTimePattern");
        System.out.println("过滤器B初始化" + dateTimePattern);

    }

    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws
            IOException, ServletException {
        System.out.println("过滤器B放行");
       HttpServletRequest request = (HttpServletRequest) servletRequest;

        filterChain.doFilter(servletRequest, servletResponse);
    }
}